package cn.tedu;
//封装工具类
import java.sql.*;

public class jdbcUtility {
    public  static Connection getConnection() throws Exception {
        //1.注册驱动jar包
        Class.forName("com.mysql.jdbc.Driver");
        //2.连接数据库
        String url ="jdbc:mysql://localhost:3306/jdbctest?characterEncoding=utf8"+"?characterEncoding=utf8";
        Connection con= DriverManager.getConnection(url,"root","root");
        return con;
    }
    public static void close(ResultSet rs, PreparedStatement ps,Connection con){
        //6.释放资源
        if(rs!=null){
            try {
                rs.close();
            } catch (Exception e) {
                e.printStackTrace();
            }finally {
                rs=null;
            }
            if(ps!=ps) {
                try {
                    ps.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }finally {
                    ps=null;
                }
            }
            if(con!=null) {
                try {
                    con.close();
                } catch (SQLException throwables) {
                    throwables.printStackTrace();
                }finally {
                    con=null;
                }
            }
        }
    }

}
